<layout name="layout_admin" />

<div class="pageheader notab">
	<ul class="breadcrumbs breadcrumbs2"  >
		<li>
			<a href="/algorithm/condition">思路平台</a><span class="divider">&#187;</span>
		</li>
		<li>思路分类</li>
	</ul>
</div>
<link rel="stylesheet" href="/Js/dist/treeview/jquery.treeview.css">
<link rel="stylesheet" href="/Js/dist/upload/jquery.fileupload.css">
<link rel="stylesheet" href="/Js/dist/simditor/simditor.css">
<style>
	.contentwrapper {
		padding-right: 10px; 
	}
	.silu-left{
		width: 400px;
	}
	.silu-right{
		width: 50%;
	}
	.silu-left {
		float: left;
	}
	.silu-right{
		display: inline-block;
		/*background: green;*/
		border: 1px solid #d1d1d1;
		margin-left: 100px;
	}
	.box-tools {
		display: none;
		float: right;
	}
	.box-tools .menu-edit,.box-tools .menu-add,.box-tools .menu-delete{
		display: inline-block;
		width: 17px;
		height: 17px;
		margin-left: 5px;
		float: left;
	}
	.box-tools .menu-edit {
		background: url(/Img/sprites.png) -163px -270px no-repeat;
	}
	.box-tools .menu-add {
		background: url(/Img/sprites.png) -55px -126px no-repeat;
	}
	.box-tools .menu-delete {
		background: url(/Img/sprites.png) -57px -18px no-repeat;
	}
	.nolborder {
		border: none;
	}
	.toPlatform {
		margin-left: -10px;
	}

	.toPlatform .v1{
		margin: 0px 0px 0px 10px;
		float: left;
	}
	.toPlatform .v1:first-child{
		margin-left: 0px;
	}

	#menu_name {
		width: 200px;
	}

	/*cusstom simdeidt css*/
	.simditor .simditor-body{
		min-height: 100px;
	}

	/*upload css*/
	.show-upload {
		width: 250px;
		height: 160px;
	}
	.silu-pic-upload {
		display: inline-block;
		height: 160px;
		line-height: 160px;
		margin-left: 20px;
	}
	.a-upload {
		padding: 4px 10px;
		height: 20px;
		line-height: 20px;
		position: relative;
		cursor: pointer;
		color: #888;
		background: #fafafa;
		border: 1px solid #ddd;
		border-radius: 4px;
		overflow: hidden;
		display: inline-block;
		*display: inline;
		*zoom: 1
	}

	.a-upload  input {
		position: absolute;
		font-size: 100px;
		right: 0;
		top: 0;
		opacity: 0;
		filter: alpha(opacity=0);
		cursor: pointer
	}

	.a-upload:hover {
		color: #444;
		background: #eee;
		border-color: #ccc;
		text-decoration: none
	}

	.silu-pic {
		float: left;
	}
</style>

<div id="contentwrapper" class="contentwrapper">
	<div id="maincontent">
		<div class="silu-left">
			{$menuTree}
		</div>
		<div class="silu-right">
			<table class="metrotable">
				<tbody>
					<tr>
						<td width="100px">名称：</td>
						<td>
							<input type="text" name="menu_name" id="menu_name">
						</td>
					</tr>
					<tr>
						<td>
							栏目：
							<input type="hidden" id="platform" name="menu_path" value="">
						</td>
						<td class="toPlatform" data-rel="true"></td>
					</tr>
					<tr>
						<td>大图：</td>
						<td>
							<div class="silu-pic">
								<img src="/Img/img/default.jpg" id="show_upload" class="show-upload">
							</div>
							<div class="silu-pic-upload">
								<span class="a-upload">
									<i class="glyphicon glyphicon-plus"></i>
									<span class="a_upload">点击选择文件</span>
									<input id="fileupload" type="file" name="files">
								</span>
							</div>
							<input type="hidden" id="menu_icon" value="/Img/img/default.jpg">
						</td>
					</tr>
					<tr>
						<td>栏目说明：</td>
						<td>
							<textarea id="summary" data-autosave="editor-content" autofocus></textarea>
						</td>
					</tr>
					<tr>
						<td>是否显示：</td>
						<td>
							<input type="checkbox" checked id="status">
						</td>
					</tr>
					<tr>
						<td style="border:none;padding-left:100px;padding-top:30px;" colspan="2">
							<button class="stdbtn menuBtn">保存</button>
							<input type="hidden" id="modelType" value="add">
							<input type="hidden" id="menu_id">
							<!-- <button class="stdbtn">撤销</button> -->
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>
<script>
	$(document).ready(function(){
		$("#browser").treeview();
		getTree('', true, false);
		
	});

	var toolbar = ['bold', 'italic', 'underline', 'strikethrough', 'fontScale', 'color', '|', 'ol', 'ul','|', 'link', 'image', 'hr', '|', 'indent', 'outdent', 'alignment'];
	var editor = new Simditor({
	textarea: $('#summary'),
		placeholder: '策略说明...',
		toolbar: toolbar,
		defaultImage : '/Img/img/default.jpg',
		upload : {
		    url : '/bug/uploads', //文件上传的接口地址
		    params: null, //键值对,指定文件上传接口的额外参数,上传的时候随文件一起提交
		    fileKey: '', //服务器端获取文件数据的参数名
		    connectionCount: 3,
		    leaveConfirm: '正在上传文件',
		    // ext : ''
		},
		toolbarFloat : true
	});
	

	$('.folder,.file,.box-tools').hover(function() {
		var $this = $(this),
			path = $this.parent('li').data('path');
		$('.menu-tools-'+path).css('display', 'inline-block');
	}, function() {
		var $this = $(this),
			path = $this.parent('li').data('path');
		$('.menu-tools-'+path).css('display', 'none');
	});

	$('.box-tools').on('click', '.menu-edit', function() {
		var $this = $(this),
			id = $this.parents('li').data('id');
		$.post('/algorithm/getMenuInfo', {menu_id : id}, function(res) {
			var info = res.data;
			if(info.error == 0) {
				$('#menu_name').val(info.item.menu_name);
				$('#platform').val(info.item.menu_path);
				$('.toPlatform').html(info.item.menu_path_select);
				$('#show_upload').attr('src', info.item.menu_icon);
				$('#menu_icon').val(info.item.menu_icon);
				$("#modelType").val('edit');
				$("#menu_id").val(id);
				editor.setValue(info.item.summary);
				info.item.status == 1 ? $('#status').attr("checked",'checked') : $('#status').attr("checked", false);
			} else {
				msg.msg(info.msg, {
					time : 0,
					btn :['确定']
				})
			}
		},'json');
	}).on('click', '.menu-add', function() {
		msg.msg('add');
	}).on('click', '.menu-delete', function() {
		var $this = $(this),
		id = $this.parents('li').data('id');
		msg.msg('确定要删除吗？', {
			time : 0,
			btn : ['确定','取消'],
			yes: function(index) {
							$.post('/algorithm/delMenu', {menu_id : id}, function(res) {
								if(res.data.status == 1)
									msg.msg('删除成功', {
										time : 0,
										btn : ['确定'],
										yes : function(index) {
											window.location.reload();
										}
									})
								else
									msg.msg(res.data.msg, {
										time : 0,
										btn : ['确定']
									});
							}, 'json');
						}
				
		})
	})

	$('#fileupload').fileupload({
		paramName: 'imgFile',
		url: '/bug/uploads?dir=silu',
		dataType: 'json',
		done: function(e, data) {
			if (data.result.error == 0) {
				$("#show_upload").attr('src', data.result.url);
				$("#menu_icon").val(data.result.url);
			} else {
				msg.msg(data.result.message);
			}
		}
	}).prop('disabled', !$.support.fileInput)
		.parent().addClass($.support.fileInput ? undefined : 'disabled');

	$('.menuBtn').click(function() {
		
		var $this = $(this),
			data = {
				menu_name : $('#menu_name').val(),
				menu_path : $('#platform').val(),
				menu_icon : $('#menu_icon').val(),
				summary : editor.getValue(),
				status : $('#status').is(':checked') ? 1 : 0
			};
		if(data.menu_name == '') {
			msg.msg('请正确填写策略名称', {
				time : 0,
				btn : ['确定']
			});
			return false;
		}
		if(data.menu_path == '') {
			msg.msg('请正确选择所属策略', {
				time : 0,
				btn : ['确定']
			});
			return false;
		}

		if($("#modelType").val() == 'edit')
			data.menu_id = $("#menu_id").val()
		
		wt.post('/algorithm/addMenu', data, function(a) {
			var o = $.parseJSON(a);
			if(o.data.status == 1)
				window.location.reload();
			else
				msg.msg(o.data.msg, {
					time : 0,
					btn :['确定']
				})
		})
	});
</script>